home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.src.lzh / relay / mkdirs.c < prev    next >
C/C++ Source or Header  |  1989-07-09  |  944b  |  50 lines

  1. /*
  2.  * mkdirs - make the directories implied by `name'
  3.  */
  4.  
  5. #include <stdio.h>
  6. #ifndef AMIGA
  7. # include <sys/types.h>
  8. # include <sys/stat.h>
  9. #else
  10. # include <libraries/dos.h>
  11. #endif /* AMIGA */
  12. #include "libc.h"
  13. #include "news.h"
  14.  
  15. /*
  16.  * Given a/b/c/d, try to make any of a, a/b, a/b/c, and a/b/c/d which
  17.  * are missing; stop on first failure.
  18.  * Returns success.
  19.  */
  20.  
  21. boolean mkdirs(name, uid, gid)
  22. register char *name;
  23. int uid, gid;
  24. {
  25.     register char *cp;
  26.     register int isthere = YES;
  27. #ifndef AMIGA
  28.     struct stat stbuf;
  29. #else
  30.     struct FileLock *lock, *Lock();
  31. #endif /* AMIGA */
  32.  
  33.     for (cp = name; isthere && *cp != '\0'; cp++)
  34.         if (*cp == FNDELIM) {
  35.             *cp = '\0';
  36. #ifdef AMIGA
  37.             if (lock = Lock(name)) UnLock(lock);
  38.             else isthere = NO;
  39. #else
  40.             isthere = stat(name, &stbuf) >= 0;
  41. #endif /* AMIGA */
  42.             if (!isthere) {
  43.                 isthere = mkdir(name /* , 0777 */) >= 0;
  44.                 (void) chown(name, uid, gid);
  45.             }
  46.             *cp = FNDELIM;
  47.         }
  48.     return isthere;
  49. }
  50.